/*
 * Created by JFormDesigner on Wed Jun 19 16:18:40 CST 2024
 */

package 作业;

import javax.swing.*;
import javax.swing.GroupLayout;
import java.awt.event.ActionEvent;
import java.sql.SQLException;
import java.util.Vector;

/**
 * @author RYTHON
 */
public class AdOrder extends JFrame {
    public AdOrder() throws SQLException {
        initComponents();
    }

    private void initComponents() throws SQLException {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        scrollPane1 = new JScrollPane();
        setTitle("订单管理");
        Vector title=new Vector();
        title.add("用户名");
        title.add("始发地");
        title.add("终点");
        title.add("实付金额");
        title.add("购买时间");
        title.add("发车时间");
        Vector text=Getdb.op.GetET();
        table1 = new JTable(text,title);
        button1 = new JButton();

        button1.setAction(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (table1.getSelectedRow()<0){
                    JOptionPane.showMessageDialog(null,"你还没有选择");
                }
                else{
                    try{
                        int row=table1.getSelectedRow();
                        Getdb.op.del((String) table1.getValueAt(row,0), (String) table1.getValueAt(row,5));
                        JOptionPane.showMessageDialog(null,"成功");
                        dispose();
                        new AdOrder().setVisible(true);
                    } catch (SQLException ex) {
                        JOptionPane.showMessageDialog(null,"失败");
                    }
                }
            }
        });

        //======== this ========
        var contentPane = getContentPane();

        //======== scrollPane1 ========
        {
            scrollPane1.setViewportView(table1);
        }

        //---- button1 ----
        button1.setText("取消订单");

        GroupLayout contentPaneLayout = new GroupLayout(contentPane);
        contentPane.setLayout(contentPaneLayout);
        contentPaneLayout.setHorizontalGroup(
            contentPaneLayout.createParallelGroup()
                .addGroup(contentPaneLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(scrollPane1, GroupLayout.DEFAULT_SIZE, 711, Short.MAX_VALUE)
                    .addContainerGap())
                .addGroup(contentPaneLayout.createSequentialGroup()
                    .addGap(309, 309, 309)
                    .addComponent(button1)
                    .addContainerGap(336, Short.MAX_VALUE))
        );
        contentPaneLayout.setVerticalGroup(
            contentPaneLayout.createParallelGroup()
                .addGroup(contentPaneLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(scrollPane1, GroupLayout.PREFERRED_SIZE, 291, GroupLayout.PREFERRED_SIZE)
                    .addGap(26, 26, 26)
                    .addComponent(button1)
                    .addContainerGap(16, Short.MAX_VALUE))
        );
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    private JScrollPane scrollPane1;
    private JTable table1;
    private JButton button1;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}
